import { ElMessage, ElMessageBox } from 'element-plus';
// import useTable from './useTable';
// import * as http from '@/request/http';
// const { queryList } = useTable(http.homeAdvertise.getAdvertiseList, {})
export default function useSwitchStatus<P, P2, IStatusRes>(reqApi: (params: P) => RES<IStatusRes>, row: any, reqApi2: (params: P2) => RES<any>, row2: any) {


    ElMessageBox.confirm(
        '是否要修改上线/下线状态?',
        'Warning',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
        }).then(() => {
            reqApi({ ...row }).then(res => {
                if (res.code === 200) {

                    // queryList()
                    ElMessage.success('更新成功');
                    reqApi2({ ...row2 }).then(res => {
                        console.log(res);
                    })
                } else {
                    row.status = row.status == 1 ? 0 : 1;
                    ElMessage.success('更新失败');
                }

            }).catch(err => {
                console.log(err);
                row.status = row.status == 1 ? 0 : 1;
            });
        }).catch(() => {
            row.status = row.status == 1 ? 0 : 1
            console.log(row.status);
            ElMessage.success('已取消操作')
            // queryList()

            reqApi2({ ...row2 }).then(res => {
                console.log(res);
                console.log(row.status);
            })
        })
}